#include "lxz_config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "lxz_types.h"
#include "os_port.h"
#include "lxz_runlog.h"
#include "lxz_debug.h"
#include "lxz_ring.h"
#include "lxz_string.h"
#include "lxz_dstring.h"
#include "lxz_atc_req.h"
#include "lxz_dbg_vmem.h"

#ifdef LXZAT_CCORE
  extern lxzat_info_t lai_and_f0;
  extern lxzat_info_t lai_and_w;
  extern lxzat_info_t lai_and_z;
  extern lxzat_info_t lai_null_i;
  extern lxzat_info_t lai_null_o;
  extern lxzat_info_t lai_null_e0;
  extern lxzat_info_t lai_null_e1;
  extern lxzat_info_t lai_null_s1;
  extern lxzat_info_t lai_null_s2;
  extern lxzat_info_t lai_null_s3;
  extern lxzat_info_t lai_null_s4;
  extern lxzat_info_t lai_null_s5;
  extern lxzat_info_t lai_null_v0;
  extern lxzat_info_t lai_null_v1;
  extern lxzat_info_t lai_null_e0v1;
  extern lxzat_info_t lai_plus_csq;
  extern lxzat_info_t lai_plus_gmr;
  extern lxzat_info_t lai_plus_cclk;
  extern lxzat_info_t lai_plus_cpin;
  extern lxzat_info_t lai_plus_cimi;
  extern lxzat_info_t lai_plus_cmee;
  extern lxzat_info_t lai_plus_cnum;
  extern lxzat_info_t lai_plus_cfun;
  extern lxzat_info_t lai_plus_ccid;
  extern lxzat_info_t lai_plus_cgsn;
  extern lxzat_info_t lai_plus_cgmi;
  extern lxzat_info_t lai_plus_cgmm;
  extern lxzat_info_t lai_plus_cgmr;
  extern lxzat_info_t lai_plus_creg;
  extern lxzat_info_t lai_plus_cgreg;
  extern lxzat_info_t lai_plus_cereg;
  extern lxzat_info_t lai_plus_cops;
  extern lxzat_info_t lai_plus_ipr;
  extern lxzat_info_t lai_plus_cgpco;
  extern lxzat_info_t lai_plus_cgdcont;
  extern lxzat_info_t lai_plus_cgact;
  extern lxzat_info_t lai_plus_cgpaddr;
  extern lxzat_info_t lai_plus_crsm;
  extern lxzat_info_t lai_plus_cscs;
#endif /* LXZAT_CCORE */

#ifdef LXZAT_CALC
  extern lxzat_info_t lai_plus_dcadd;
  extern lxzat_info_t lai_plus_dcdel;
  extern lxzat_info_t lai_plus_dcmul;
  extern lxzat_info_t lai_plus_dcdiv;
  extern lxzat_info_t lai_plus_dcstradd;
  extern lxzat_info_t lai_plus_dcstrdel;
#endif /* LXZAT_CALC */

#ifdef LXZAT_BASIC
  extern lxzat_info_t lai_dollar_mydbgtime;
  extern lxzat_info_t lai_dollar_mydbgdate;
  extern lxzat_info_t lai_dollar_mydbgauthor;
  extern lxzat_info_t lai_dollar_myhwver;
  extern lxzat_info_t lai_dollar_myswver;
  extern lxzat_info_t lai_dollar_mydbgatlist;
  extern lxzat_info_t lai_dollar_mysystemcfg;
  extern lxzat_info_t lai_dollar_mytypemask;
  extern lxzat_info_t lai_dollar_mycimi;
  extern lxzat_info_t lai_dollar_mycgsn;
  extern lxzat_info_t lai_dollar_mycgmi;
  extern lxzat_info_t lai_dollar_mycgmm;
  extern lxzat_info_t lai_dollar_mycgmr;
#endif /* LXZAT_BASIC */

#ifdef LXZAT_HWIP
  extern lxzat_info_t lai_caret_curc;
  extern lxzat_info_t lai_caret_ipinit;
  extern lxzat_info_t lai_caret_ipopen;
  extern lxzat_info_t lai_caret_ipsend;
  extern lxzat_info_t lai_caret_ipclose;
  extern lxzat_info_t lai_caret_ipsendex;
#endif /* LXZAT_HWIP */

#ifdef LXZAT_LSIP
  extern lxzat_info_t lai_plus_mipurc;
  extern lxzat_info_t lai_plus_mipcall;
  extern lxzat_info_t lai_plus_mipopen;
  extern lxzat_info_t lai_plus_mipmode;
  extern lxzat_info_t lai_plus_mipwrite;
  extern lxzat_info_t lai_plus_mipread;
  extern lxzat_info_t lai_plus_mipreread;
  extern lxzat_info_t lai_plus_mipput;
  extern lxzat_info_t lai_plus_mipget;
  extern lxzat_info_t lai_plus_mipquery;
  extern lxzat_info_t lai_plus_mipclose;
  extern lxzat_info_t lai_plus_mdnsquery;
#endif /* LXZAT_LSIP */

#ifdef LXZAT_SGCC
  extern lxzat_info_t lai_dollar_mypoweroff;
  extern lxzat_info_t lai_dollar_mysocketled;
  extern lxzat_info_t lai_dollar_mygmr;
  extern lxzat_info_t lai_dollar_myccid;
  extern lxzat_info_t lai_dollar_myneturc;
  extern lxzat_info_t lai_dollar_mytype;
  extern lxzat_info_t lai_dollar_mynetcon;
  extern lxzat_info_t lai_dollar_mynetact;
  extern lxzat_info_t lai_dollar_myipfilter;
  extern lxzat_info_t lai_dollar_mynetsrv;
  extern lxzat_info_t lai_dollar_mynetopen;
  extern lxzat_info_t lai_dollar_mynetread;
  extern lxzat_info_t lai_dollar_mynetwrite;
  extern lxzat_info_t lai_dollar_mynetclose;
  extern lxzat_info_t lai_dollar_mynetack;
  extern lxzat_info_t lai_dollar_mynetaccept;
  extern lxzat_info_t lai_dollar_mynetcreate;
  extern lxzat_info_t lai_dollar_myftpopen;
  extern lxzat_info_t lai_dollar_myftpclose;
  extern lxzat_info_t lai_dollar_myftpsize;
  extern lxzat_info_t lai_dollar_myftpget;
  extern lxzat_info_t lai_dollar_myftpput;
  extern lxzat_info_t lai_dollar_mybcch;
  extern lxzat_info_t lai_dollar_myband;
  extern lxzat_info_t lai_dollar_mygpspos;
  extern lxzat_info_t lai_dollar_mysysinfo;
  extern lxzat_info_t lai_dollar_mysysmode;
  extern lxzat_info_t lai_dollar_mymodem;
  extern lxzat_info_t lai_dollar_mynetinfo;
  extern lxzat_info_t lai_dollar_mynetorder;
  extern lxzat_info_t lai_dollar_mysystemupdate;
  extern lxzat_info_t lai_dollar_mynetput;
  extern lxzat_info_t lai_dollar_mynetget;
  extern lxzat_info_t lai_dollar_mytimeset;
  extern lxzat_info_t lai_dollar_mytimeget;
  extern lxzat_info_t lai_dollar_mytimentp;
  extern lxzat_info_t lai_dollar_mydnsquery;
  extern lxzat_info_t lai_dollar_myurcsysinfo;
  extern lxzat_info_t lai_dollar_myipr;
  extern lxzat_info_t lai_dollar_mynetwget;
#endif /* LXZAT_SGCC */

#ifdef LXZAT_FILE
  extern lxzat_info_t lai_dollar_myfileopen;
  extern lxzat_info_t lai_dollar_myfilewrite;
  extern lxzat_info_t lai_dollar_myfileread;
  extern lxzat_info_t lai_dollar_myfileclose;
  extern lxzat_info_t lai_dollar_myfilesize;
  extern lxzat_info_t lai_dollar_myfiledelete;
  extern lxzat_info_t lai_dollar_myfilequery;
  extern lxzat_info_t lai_dollar_myfileput;
  extern lxzat_info_t lai_dollar_myfileget;
  extern lxzat_info_t lai_dollar_myfilewget;
#endif /* LXZAT_FILE */
  
const lxzat_info_t *lxzat_ai_table[] =
{
#ifdef LXZAT_CCORE
    &lai_and_f0,
    &lai_and_w,
    &lai_and_z,
    &lai_null_i,
    &lai_null_o,
    &lai_null_e0,
    &lai_null_e1,
    &lai_null_s1,
    &lai_null_s2,
    &lai_null_s3,
    &lai_null_s4,
    &lai_null_s5,
    &lai_null_v0,
    &lai_null_v1,
    &lai_null_e0v1,
    &lai_plus_csq,
    &lai_plus_gmr,
    &lai_plus_cclk,
    &lai_plus_cpin,
    &lai_plus_cimi,
    &lai_plus_cmee,
    &lai_plus_cnum,
    &lai_plus_cfun,
    &lai_plus_ccid,
    &lai_plus_cgsn,
    &lai_plus_cgmi,
    &lai_plus_cgmm,
    &lai_plus_cgmr,
    &lai_plus_creg,
    &lai_plus_cgreg,
    &lai_plus_cereg,
    &lai_plus_cops,
    &lai_plus_ipr,
    &lai_plus_cgpco,
    &lai_plus_cgdcont,
    &lai_plus_cgact,
    &lai_plus_cgpaddr,
    &lai_plus_crsm,
    &lai_plus_cscs,
#endif /* LXZAT_CCORE */

#ifdef LXZAT_SGCC
    &lai_dollar_mypoweroff,
    &lai_dollar_mysocketled,
    &lai_dollar_myccid,
    &lai_dollar_mygmr,
    &lai_dollar_myneturc,
    &lai_dollar_mytype,
    &lai_dollar_mynetcon,
    &lai_dollar_mynetact,
    &lai_dollar_myipfilter,
    &lai_dollar_mynetsrv,
    &lai_dollar_mynetopen,
    &lai_dollar_mynetread,
    &lai_dollar_mynetwrite,
    &lai_dollar_mynetclose,
    &lai_dollar_mynetack,
    &lai_dollar_mynetaccept,
    &lai_dollar_mynetcreate,
    &lai_dollar_myftpopen,
    &lai_dollar_myftpclose,
    &lai_dollar_myftpsize,
    &lai_dollar_myftpget,
    &lai_dollar_myftpput,
    &lai_dollar_mybcch,
    &lai_dollar_myband,
    &lai_dollar_mygpspos,
    &lai_dollar_mysysinfo,
    &lai_dollar_mysysmode,
    &lai_dollar_mymodem,
    &lai_dollar_mynetinfo,
    &lai_dollar_mynetorder,
    &lai_dollar_mynetput,
    &lai_dollar_mynetget,
    &lai_dollar_mytimeset,
    &lai_dollar_mytimeget,
    &lai_dollar_mytimentp,
    &lai_dollar_mydnsquery,
    &lai_dollar_myurcsysinfo,
    &lai_dollar_myipr,
    &lai_dollar_mynetwget,
#endif /* LXZAT_SGCC */

#ifdef LXZAT_FILE
    &lai_dollar_myfileopen,
    &lai_dollar_myfilewrite,
    &lai_dollar_myfileread,
    &lai_dollar_myfileclose,
    &lai_dollar_myfilesize,
    &lai_dollar_myfiledelete,
    &lai_dollar_myfilequery,
    &lai_dollar_myfileput,
    &lai_dollar_myfileget,
    &lai_dollar_myfilewget,
#endif /* LXZAT_FILE */

#ifdef LXZAT_HWIP
    &lai_caret_curc,
    &lai_caret_ipinit,
    &lai_caret_ipopen,
    &lai_caret_ipsend,
    &lai_caret_ipclose,
    &lai_caret_ipsendex,
#endif /* LXZAT_HWIP */

#ifdef LXZAT_LSIP
    &lai_plus_mipurc,
    &lai_plus_mipcall,
    &lai_plus_mipopen,
    &lai_plus_mipmode,
    &lai_plus_mipwrite,
    &lai_plus_mipread,
    &lai_plus_mipreread,
    &lai_plus_mipput,
    &lai_plus_mipget,
    &lai_plus_mipquery,
    &lai_plus_mipclose,
    &lai_plus_mdnsquery,
#endif /* LXZAT_LSIP */

#ifdef LXZAT_BASIC
    &lai_dollar_mydbgtime,
    &lai_dollar_mydbgdate,
    &lai_dollar_mydbgauthor,
    &lai_dollar_myhwver,
    &lai_dollar_myswver,
    &lai_dollar_mydbgatlist,
    &lai_dollar_mysystemcfg,
    &lai_dollar_mytypemask,
    &lai_dollar_mycimi,
    &lai_dollar_mycgsn,
    &lai_dollar_mycgmi,
    &lai_dollar_mycgmm,
    &lai_dollar_mycgmr,
#endif /* LXZAT_BASIC */

#ifdef LXZAT_CALC
    &lai_plus_dcadd,
    &lai_plus_dcdel,
    &lai_plus_dcmul,
    &lai_plus_dcdiv,
    &lai_plus_dcstradd,
    &lai_plus_dcstrdel,
#endif /* LXZAT_CALC */

    NULL
};

const lxzat_info_t *lxzat_uat_header_table[] =
{
#ifdef LXZAT_UNIQUE_PPP
    &lai_null_dasterisk99,
    &lai_null_dtasterisk99,
#endif /* LXZAT_UNIQUE_PPP */

    NULL
};

/*
 *  Description:
 *    find an at-information descriptor.
 *  Param: i_index_id, a specified index
 *  Return: an at-information descriptor;
 */
const lxzat_info_t * lxzat_info_f_get(sint32 i_index_id)
{
    sint32 i_ai_num = 0;
    
    i_ai_num = sizeof(lxzat_ai_table)/sizeof(lxzat_ai_table[0]);
    if (i_index_id < i_ai_num)
    {
        return lxzat_ai_table[i_index_id];
    }
    
    return NULL;
}

/*
 *  Description:
 *    find an at-information descriptor.
 *  Param: i_index_id, a specified index
 *  Return: an at-information descriptor;
 */
const lxzat_info_t * lxzat_uat_f_get(sint32 i_index_id)
{
    sint32 i_uat_num = 0;
    
    i_uat_num = sizeof(lxzat_uat_header_table)/sizeof(lxzat_uat_header_table[0]);
    if (i_index_id < i_uat_num)
    {
        return lxzat_uat_header_table[i_index_id];
    }
    
    return NULL;
}

